from marshmallow import ValidationError


class LengthValidator:
    def __init__(self, min=0, max=None):
        self.min = min
        self.max = max

    def __call__(self, value):
        length = len(value)
        if not self.min < length:
            raise ValidationError('too short')
        if self.max and length > self.max:
            raise ValidationError('too long')
        return True
